<link rel="stylesheet" href="/packages/resource/pintuer/pintuer.css">

<div class="pintuer">
    <div class="padding">
        <h5 class="text-yellow">
            微分销订单统计
        </h5>

        <hr class="bg-yellow">


        <div class="line margin-top">
            <form action="/admin" class="form-inline">
                <input type="hidden" name="act" value="proxy_order">
                <input type="hidden" name="op" value="we_distribute">

                <div class="form-group">
                    <div class="field">
                        <div class="input-group">
                            <span class="addon">
                                开始时间：
                            </span>
                            <input type="date" class="input" name="start_time"
                                   value="<?php echo $_GET['start_time'] ?>">
                        </div>
                        <div class="input-group">
                            <span class="addon">
                                开始时间：
                            </span>
                            <input type="date" class="input" name="end_time" value="<?php echo $_GET['end_time'] ?>">
                        </div>

                        <div class="input-group">
                            <span class="addon">购买人ID</span>
                            <input type="text" name="buyer_name" class="input" value="<?php echo $_GET['buyer_name'] ?>">
                        </div>
                        <div class="input-group">
                            <span class="addon">收益人ID</span>
                            <input type="text" name="get_name" class="input" value="<?php echo $_GET['get_name'] ?>">
                        </div>

                        <div class="margin-top">
                        </div>

                        <div class="input-group">
                            <span class="addon">订单号</span>
                            <input type="text" name="order_id" class="input" value="<?php echo $_GET['order_id'] ?>">
                        </div>

                        <div class="button-group">
                            <button type="submit" class="button bg-blue">检索</button>

                        </div>
                    </div>
                </div>

            </form>


            <hr>

            <table class="table table-bordered">
                <tr class="thead">
                    <th>订单编号</th>
                    <th>下单时间</th>
                    <th>订单总金额</th>
                    <th>购买人</th>
                    <th>
                        收益人
                    </th>
                    <th>佣金类型</th>
                    <th>佣金</th>
                </tr>
                <?php
                    $m = Model('weproxy_order_margin');
                    $condition = array();
                    if (!empty($_GET['start_time'])) {
                        $condition['time'] = array('gt', strtotime($_GET['start_time']));
                    }

                    if (!empty($_GET['end_time'])) {
                        $condition['time'] = array('lt', strtotime($_GET['end_time']));
                    }

                    if (!empty($_GET['buyer_name'])) {
                        $member = null;
                        $member = Model('member')->where(['member_name' => $_GET['buyer_name']])->find();
                        if ($member) {
                            $condition['from_member'] = $member['member_id'];
                        }
                    }

                    if (!empty($_GET['get_name'])) {
                        $member = null;
                        $member = Model('member')->where(['member_name' => $_GET['buyer_name']])->find();
                        if ($member) {
                            $condition['member_id'] = $member['member_id'];
                        }
                        else{
                            $condition['member_id'] = -100;
                        }
                    }

                    if(!empty($_GET['order_id'])){
                        $oinfo = ml('order')->find([
                            'order_sn' => $_GET['order_id']
                        ]);
                        if($oinfo){
                            $condition['order_id'] = $oinfo['order_id'];
                        }
                        else{
                            $condition['1'] = 2;
                        }
                    }

                    $list = $m->where($condition)->page(20)->select();
                    //                    if(!empty($_GET[]))
                    if ($list) {
                        foreach ($list as $item) {

                            ?>
                            <tr>
                                <td>
                                    <a href="/admin/index.php?act=order&op=show_order&order_id=<?php echo $item['order_id']?>">
                                        <?php
                                            $oinfo = Model()->table('order')->where(array('order_id' => $item['order_id']))->find();
                                            echo $oinfo['order_sn'];
                                        ?>
                                    </a>
                                </td>
                                <td>
                                    <?php
                                        echo date('Y-m-d H:i:s', $item['time']);
                                    ?>
                                </td>
                                <td>
                                    ￥
                                    <?php echo $oinfo['order_amount'] ?>
                                </td>
                                <td>
                                    <?php
                                        echo $oinfo['buyer_name'];
                                    ?>
                                </td>
                                <td>
                                    <?php
                                        $member = Model('member')->find($item['member_id']);
                                        echo $member['member_name'];
                                    ?>
                                </td>
                                <th>
                                    <?php
                                        if($item['type'] == MARGIN_INVITER){
                                            echo "推荐人提成";
                                        }
                                        else{
                                            echo "上级提成";
                                        }
                                    ?>
                                </th>
                                <td>
                                    ￥
                                    <?php
                                        echo $item['margin'];
                                    ?>
                                </td>
                            </tr>
                            <?php
                        }

                    } else {

                    }

                ?>
            </table>

            <link rel="stylesheet" href="/packages/resource/css/pager.css">
            <div class="_pager margin-big-top">
                <?php
                    echo $m->showpage();
                ?>
            </div>
        </div>
    </div>


</div>

